package com.jxsd.edu.cn.struts2.serviceImpl;

import java.util.List;

import com.jxsd.edu.cn.struts2.dao.CatagoryDao;
import com.jxsd.edu.cn.struts2.dao.PubMsgDao;
import com.jxsd.edu.cn.struts2.dao.PublishGoodAttributeDao;
import com.jxsd.edu.cn.struts2.dao.SmallCatagoryDao;
import com.jxsd.edu.cn.struts2.daoImpl.CatagoryDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.PubMsgDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.PublishGoodAttributeDaoImpl;
import com.jxsd.edu.cn.struts2.daoImpl.SmallCatagoryDaoImpl;
import com.jxsd.edu.cn.struts2.models.Category;
import com.jxsd.edu.cn.struts2.models.PubMsgview;
import com.jxsd.edu.cn.struts2.models.PublishGoodAttribute;
import com.jxsd.edu.cn.struts2.models.SmallCatagory;
import com.jxsd.edu.cn.struts2.services.IndexService;
import com.jxsd.edu.cn.tools.Page;
import com.jxsd.edu.cn.tools.PageBean;

public class IndexServiceImpl implements IndexService 
{
    private  CatagoryDao         catagoryDao=new  CatagoryDaoImpl();
    private  SmallCatagoryDao    smallDao=new  SmallCatagoryDaoImpl();
    private  PubMsgDao           pubDao=new  PubMsgDaoImpl();
    private  PublishGoodAttributeDao  attriDao=new  PublishGoodAttributeDaoImpl();
    
	@Override
	public List<Category> getAllCatagory() 
	{
		List<Category>  list=catagoryDao.getCatagories();
		for(Category  c:list)
		{
			List<SmallCatagory>  smalllist=smallDao.getAllSmalls(Integer.toString(c.getCatagoryID()));
			c.setList(smalllist);
		}
		return list;
	}

	@Override
	public Page<PubMsgview> getPagePubMsg(String catagoryId,PageBean<PubMsgview>  pagebean,String cityName) 
	{
		Page<PubMsgview>  page=null;
		page=pubDao.getNewlyPubMsg(catagoryId, pagebean,cityName);
		if(0==page.getList().size())
		{
			cityName="南昌";
			page=pubDao.getNewlyPubMsg(catagoryId, pagebean,cityName);
		}
		
		for(PubMsgview  msg:page.getList())
		{
			List<PublishGoodAttribute>  attributes=attriDao.getHotAttributes(Integer.toString(msg.getPublishID()));
			msg.setAttributes(attributes);
		}
		return page;
	}

}
